package com.cd.university.controller;

import com.cd.university.common.RestResult;
import com.cd.university.controller.form.PEByDeIdAndStatusIdForm;
import com.cd.university.service.ProjectExamineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈栋
 * @create 2021/11/1 20:57
 */
@RestController
@RequestMapping("/pe")
@Api("项目初审接口")
public class ProjectExamineController {

    @Autowired
    private ProjectExamineService projectExamineService;

    @GetMapping("/getAll/{flag}")
    @ApiOperation("获得所有的初审的审核项目")
    public RestResult findAllProject(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                     @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                     @PathVariable("flag") Integer flag) {
        return projectExamineService.findAllProject(pageNum, pageSize,flag);
    }


    @GetMapping("/searchPEByName/{flag}")
    @ApiOperation("通过审核项目名称搜索")
    public RestResult searchPEByName(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                     @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                     @RequestParam(required = true) String projectName,
                                     @PathVariable("flag") Integer flag) {
        return projectExamineService.searchPEByName(pageNum, pageSize, projectName,flag);
    }



    @GetMapping("/searchPEByDeId/{flag}")
    @ApiOperation("通过审核项目的单位id查询审核项目")
    public RestResult searchPEByDepartmentId(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                             @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                             @RequestParam(required = true) Integer departmentId,
                                             @PathVariable("flag") Integer flag) {
        return projectExamineService.searchPEByDepartmentId(pageNum, pageSize, departmentId, flag);
    }

    @GetMapping("/approved/{flag}")
    @ApiOperation("通过审核项目(一审和二审)")
    public RestResult approvedExamine(@RequestParam("peId") Integer peId,
                                      @RequestParam("reviewerId") Integer reviewerId,
                                      @PathVariable("flag") Integer flag) {
        return projectExamineService.approvedExamine(peId, reviewerId,flag);
    }

    @PostMapping("/searchPEByDeIdAndSId/{flag}")
    @ApiOperation("根据项目的单位还有状态查询")
    public RestResult searchPEByDeIdAndSId(@RequestBody PEByDeIdAndStatusIdForm form,
                                           @PathVariable("flag") Integer flag) {
        return projectExamineService.searchPEByDeIdAndSId(form.getPageNum(),
                form.getPageSize(), form.getDepartmentId(), form.getStatusId(), flag);
    }

    @PostMapping("/getAllByStAndDe/{flag}")
    @ApiOperation("万能接口")
    public RestResult searchPEByStAndDe(@RequestBody PEByDeIdAndStatusIdForm form,
                                        @PathVariable("flag") Integer flag) {
        return projectExamineService.searchPEByStAndDe(form.getPageNum(), form.getPageSize(),
                form.getDepartmentId(),form.getStatusId(),flag);
    }


}
